<?php
/**
 * Created by PhpStorm.
 * User: Hk
 * Date: 2021/2/3
 * Time: 14:22
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Models\Announcement;
use Illuminate\Http\Request;

class AnnouncementController extends Controller
{
    public $model;
    public function __construct(){
        $this->model = new Announcement();
    }

    /**
     * Notes: 列表
     * User: HK
     * Date: 2021/2/3
     * Time: 14:47
     * email: 1919194843@qq.com
     * @return mixed
     */
    public function index()
    {
        return $this->model->getPaginate( ['status' => 1]);
    }

    /**
     * Notes: 添加
     * User: HK
     * Date: 2021/2/3
     * Time: 14:31
     * email: 1919194843@qq.com
     */
    public function store(Request $request)
    {
        return $this->model->create( $request->post() ) ? $this->success('添加成功!') : $this->error('添加失败!');
    }

    /**
     * Notes: 展示
     * User: HK
     * Date: 2021/2/3
     * Time: 14:47
     * email: 1919194843@qq.com
     */
    public function show ($id)
    {
        return $this->success( $this->model->getInfoById( $id ) );
    }

    /**
     * Notes: 修改
     * User: HK
     * Date: 2021/2/3
     * Time: 14:49
     * email: 1919194843@qq.com
     */
    public function update (Request $request)
    {
        $data = $request->post();
        return $this->model->updateById( $data['id'] , $data) ? $this->success('添加成功!') : $this->error('添加失败!');
    }

    /**
     * Notes: 删除
     * User: HK
     * Date: 2021/2/3
     * Time: 14:52
     * email: 1919194843@qq.com
     */
    public function destroy ( $ids )
    {
        return $this->model->deletes( $ids ) ? $this->success('删除成功!') : $this->error('删除失败!');
    }
}
